#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int b[N];
vector<int> adj[N];
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    for (int i = 0; i <= n + 1; ++i) adj[i].clear();
    int k = 0;
    for (int i = 1; i <= n; ++i) {
      cin >> b[i];
      if (b[i] > i) k = i;
      adj[b[i]].push_back(i);
    }

    int root = adj[0].size() ? 0 : n + 1;
    vector<int> q = {root};
    for (int i = 0; i < q.size(); ++i) {
      int x = q[i];
      sort(adj[x].begin(), adj[x].end(),
           [&](int a, int b) { return adj[a].size() < adj[b].size(); });
      for (auto y : adj[x]) q.push_back(y);
    }

    printf("%d\n", k);

    for (int i = 1; i < (int)q.size(); ++i) {
      if (i > 1) printf(" ");
      printf("%d", q[i]);
    }
    puts("");
  }
}
